-- damage_beheaded
-- create by wangy
-- 对目标施加伤害,概率斩杀生命值低于%的敌人

return {
    apply = function(source, target, skillId, round, para, extra)
        -- 威力
        local force = para[1];

        -- 每多一个同类技能威力+
        local prop = PropM.combine(source, "power_resonance", skillId);
        if prop[3] > 0 then
            force = PropM.trigger(source, prop[1], prop[2], force);
        end

        -- 2. 攻击方的攻击
        local attack = source:getAttack();

        -- 被对方百分比削弱
        prop = PropM.combine(target, "weak_enemy", "attack");
        attack = PropM.apply(prop, attack);

        -- 被对方绝对值削弱
        prop = PropM.combine(target, "weak_enemy2", "attack");
        attack = PropM.apply(prop, attack);

        -- 3. 伤害
        local damage = math.modf(force * attack / 1000);

        -- 概率斩杀生命值低于%的敌人
        local rand = DungeonM.getRandSeed("damage_beheaded") % 1000;
        local alert_hp = math.modf(target:queryAttrib("max_hp") * para[3] / 1000);
        if rand < para[2] and alert_hp >= target:queryAttrib("hp") then
            damage = target:queryAttrib("hp");
        end

        -- 增加命中动作
        SkillM.getSequence(target):hit(source, target, skillId);

        -- 伤害
        CombatM.receiveDamage(source, target, damage, skillId, extra);

        -- 作用目标
        return { target, };
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        return { tonumber(arr[1]), tonumber(arr[2]), tonumber(arr[3]) };
    end,

    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para)
        return desc;
    end,
};
